<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改用户')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body>
<div class="main-content">
    <form class="form-horizontal" id="form-user-edit" th:object="${user}">
        <input name="userId" type="hidden" th:field="*{id}"/>
        <input name="deptId" type="hidden" th:field="*{deptId}" id="treeId"/>
        <h4 class="form-header h4">基本信息</h4>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">用户名称：</label>
                    <div class="col-sm-8">
                        <input name="username" placeholder="请输入用户名称" class="form-control" readonly="true" type="text"
                               maxlength="30"
                               th:field="*{username}" required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">归属部门：</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <input class="form-control" type="text" name="deptName" onclick="deptRadioTree()"
                                   id="treeName" th:value="${deptName}" required>
                            <span class="input-group-addon"><i class="fa fa-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">手机号码：</label>
                    <div class="col-sm-8">
                        <input name="phone" placeholder="请输入手机号码" class="form-control" type="text" maxlength="11"
                               th:field="*{phone}" required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">邮箱：</label>
                    <div class="col-sm-8">
                        <input name="email" class="form-control email" type="text" maxlength="20" placeholder="请输入邮箱"
                               th:field="*{email}" required>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">昵称：</label>
                    <div class="col-sm-8">
                        <input class="form-control" type="text" th:field="*{nickName}"/>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">使用状态：</label>
                    <div class="col-sm-8">
                        <div class="radio-box"
                             th:each="dict : ${@sysDictDataServiceImpl.listDictDataByTypeSign('sys_use_status')}">
                            <input type="radio" th:id="${dict.id}" name="use" th:value="${dict.dataValue}"
                                   th:field="*{use}">
                            <label th:for="${dict.id}" th:text="${dict.dataKey}"></label>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">用户性别：</label>
                    <div class="col-sm-8">
                        <select name="gender" class="form-control m-b"
                                th:with="dicts=${@sysDictDataServiceImpl.listDictDataByTypeSign('sys_user_gender')}">
                            <option th:each="dict : ${dicts}" th:text="${dict.dataKey}"
                                    th:value="${dict.dataValue}" th:field="*{gender}"></option>
                        </select>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">显示顺序：</label>
                    <div class="col-sm-8">
                        <input class="form-control" type="text" name="orderNum" id="orderNum" th:field="*{orderNum}"
                               required>
                    </div>
                </div>
            </div>
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-xs-2 control-label">备注：</label>
                    <div class="col-xs-10">
                        <textarea name="remark" maxlength="500" class="form-control" rows="3">[[*{remark}]]</textarea>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script type="text/javascript">
    const prefix = ctx + "system/user";
    const prefixDept = ctx + "system/dept";

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-user-edit').serialize());
        }
    }

    /*选择部门树*/
    function deptRadioTree() {
        const options = {
            title: '部门选择',
            width: "380",
            url: prefixDept + "/deptRadioTreeView",
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        if ($.tree.notAllowParents(tree)) {
            var body = layer.getChildFrame('body', index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }
    }
</script>
</body>
</html>